﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GeneratorLibrary.ClassGeneratorLibrary;
using GeneratorLibrary.CrudGeneratorLibrary;
using System.IO;
using GeneratorLibrary.Settings;
using GeneratorLibrary.DatabaseCompare;
using GeneratorLibrary.Client.SqlClient;

namespace ClassGeneratorExpress {
    public partial class MainForm : Form {
        public MainForm() {
            InitializeComponent();
            SettingsHelper.Initialize();
        }

        private void btnClasses_Click(object sender, EventArgs e) {
            if (comboBox1.Text.Length == 0)
                SelectFolder();
            if (comboBox1.Text.Length > 0) {
                List<IProjectInterface> list = new List<IProjectInterface>();
                list.Add(new ProjectExpressInterface(comboBox1.Text));
                new ClassGenForm(list).ShowDialog();
            }
        }

        private void btnStoredProcedures_Click(object sender, EventArgs e) {
            new CRUDForm().ShowDialog();
        }

        private void btnBrowse_Click(object sender, EventArgs e) {
            SelectFolder();
        }

        private void SelectFolder() {
            if (comboBox1.Text.Length > 0) {
                folderBrowserDialog1.SelectedPath = comboBox1.Text;
            }
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
                comboBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void MainForm_Load(object sender, EventArgs e) {
            string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            folderBrowserDialog1.SelectedPath = myDocuments;
            comboBox1.Text = myDocuments;

            comboBox1.Items.Add(myDocuments);

            if (new DirectoryInfo(@"c:\inetpub\wwwroot").Exists)
                comboBox1.Items.Add(@"c:\inetpub\wwwroot");

            if (new DirectoryInfo(myDocuments + @"\Visual Studio 2008\Projects").Exists) {
                comboBox1.Items.Add(myDocuments + @"\Visual Studio 2008\Projects");
                comboBox1.Text = myDocuments + @"\Visual Studio 2008\Projects";
            }

            if (new DirectoryInfo(myDocuments + @"\Visual Studio 2005\Projects").Exists)
                comboBox1.Items.Add(myDocuments + @"\Visual Studio 2005\Projects");
        }

        private void btnSettings_Click(object sender, EventArgs e) {
            ChangeSettings form = new ChangeSettings();
            form.ShowDialog();
        }
    }
}
